package com.example.administrator.yuejian2.fragment;


import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle;

import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.support.v4.app.Fragment;
import android.widget.AbsListView;

import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.adapter.CourseAdapter;
import com.example.administrator.yuejian2.bean.CourseBean;
import com.example.administrator.yuejian2.model.CourseModel;

import java.util.List;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

/**
 * A simple {@link Fragment} subclass.
 */
public class CourseFragment extends Fragment {

    private RecyclerView recyclerView;
    private CourseAdapter courseAdapter;
    private String c_id;
    private RecyclerView.LayoutManager layoutManager;
    private RetrofitListener<List<CourseBean>> listener;
    private JCVideoPlayerStandard currPlayer;
    public CourseFragment() {
        // Required empty public constructor
    }


    private void initView(View v)
    {
        recyclerView=v.findViewById(R.id.course_recyclerview);
        layoutManager=new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        courseAdapter=new CourseAdapter(getActivity());
        recyclerView.setAdapter(courseAdapter);
    }
    @Override
    public void onPause() {
        super.onPause();
        JCVideoPlayer.releaseAllVideos();
    }
    private void course()
    {
        CourseModel courseModel=new CourseModel();
        courseModel.courselist(c_id,listener);
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        listener=new RetrofitListener<List<CourseBean>>() {
            @Override
            public void onSuccess(List<CourseBean> courseBeans, int flag) {
                    courseAdapter.courseData(courseBeans);
            }

            @Override
            public void onFail() {

            }
        };
        View view= inflater.inflate(R.layout.fragment_course, container, false);
        initView(view);
        Intent intent=getActivity().getIntent();
        c_id=(String)intent.getStringExtra("c_uid");
        course();
        return view;
    }


}
